package com.dayuanit.pokergame;

import com.dayuanit.pokergame.rule.DoubleRuleEngine;
import com.dayuanit.pokergame.rule.RuleEngine;
import com.dayuanit.pokergame.rule.SingleRuleEngine;

import java.util.ArrayList;
import java.util.List;

public class Game {

    private static Poker[] pokers;

    private Person person1;
    private Person person2;

    //规则引擎的集合
    private static final List<RuleEngine> ruleEngineList = new ArrayList<>();

    static {
        ruleEngineList.add( new DoubleRuleEngine());
        ruleEngineList.add( new SingleRuleEngine());
    }

    public Game(Person person1, Person person2) {
        this.person1 = person1;
        this.person2 = person2;
    }

    public void start() {
        //创建扑克  最好放到static初始化代码块中，不用每次都创建扑克
        pokers = GameUtil.createaPoker();

        //洗牌
        GameUtil.shuffle(pokers);

        //发牌
        GameUtil.dealPork(pokers, person1);
        GameUtil.dealPork(pokers, person2);
    }

    //比赛结果
    public void result() {
        //通过规则引擎 计算谁的牌大小
        for (RuleEngine ruleEngine : ruleEngineList) {
            ruleEngine.juge(person1, person2);
        }

        System.out.println(person1);
        System.out.println(person2);
    }
}
